package com.zaofan.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zaofan.bean.ProductAttr;
import com.zaofan.dao.ProductAttrDao;

public class ProductAttrService {
	private ProductAttrDao productAttrDao = new ProductAttrDao();

	public void delete(ProductAttr bean) {
		productAttrDao.del(bean);
	}

	public void add(ProductAttr bean) {
		productAttrDao.add(bean);
	}

	public void update(ProductAttr bean) {
		productAttrDao.update(bean);
	}

	public List<ProductAttr> findAll(Map<String, Object> params) {
		List<ProductAttr> data = productAttrDao.findAll(params);
		if (data == null) {
			data = new ArrayList<>();
		}
		return data;
	}

	public Long count(Map<String, Object> params) {
		return productAttrDao.count(params);
	}

	public ProductAttr findById(Integer id) {
		Map<String, Object> params = new HashMap<>();
		params.put("id", id);
		return productAttrDao.findOne(params);
	}

	public Object isExit(ProductAttr productAttr) {
		Map<String, Object> params = new HashMap<>();
		params.put("productId", productAttr.getProductId());
		params.put("attrId", productAttr.getAttrId());
		params.put("attrValue", productAttr.getAttrValue());
		return productAttrDao.findOne(params);
	}

	public  List<ProductAttr> findByProductId(int productId) {
		Map<String, Object> params = new HashMap<>();
		params.put("productId", productId);
		return productAttrDao.findAll(params);
	}

	public void deleteAttrByProductId(int productId) {
		productAttrDao.deleteAttrByProductId(productId);
	}

}
